package com.hfjyz.tutor.tutor.bean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.hfjyz.base.bean.BaseBean;
import com.hfjyz.base.constant.BaseConstant;
import com.hfjyz.base.entity.TutorEntity;
import com.hfjyz.base.util.BaseUtil;
import com.hfjyz.base.util.CodeUtil;
import com.hfjyz.base.util.IdcardUtil;

public class TutorBean extends BaseBean {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1754895519444644829L;
    protected Integer id = null;
    protected String idNo;
    protected String name;
    protected int sex = -1;
    protected byte[] photo;
    protected String birthday;
    protected String type;
    protected String major;
    protected Float price;
    protected String style;
    protected String phone;
    protected String phoneBak;
    protected String cellPhone;
    protected String cellPhoneBak;
    protected String imAddress;
    protected String mailAddress;
    protected String mailAddressBak;
    protected String address;
    protected String task;
    protected String introduction;
    protected String outLine;
    protected Integer categoryId;
    protected Integer isSigned;
    protected String remark;
    protected Integer callTimes;

    public TutorBean() {
    }

    public TutorBean(TutorEntity entity) {
        setId(entity.getId());
        setIdNo(entity.getIdNo());
        setName(entity.getName());
        setSex(entity.getIsMale() ? 1 : 0);
        SimpleDateFormat sdf = new SimpleDateFormat(BaseConstant.DATE_PATTERN_BAR);
        if (entity.getBirthday() != null) {
            String date = sdf.format(entity.getBirthday());
            setBirthday(date);
        }
        setType(entity.getType());
        setMajor(entity.getMajor());
        setPrice(entity.getPrice());
        setStyle(entity.getStyle());
        setPhone(entity.getPhone());
        setPhoneBak(entity.getPhoneBak());
        setCellPhone(entity.getCellPhone());
        setCellPhoneBak(entity.getCellPhoneBak());
        setImAddress(entity.getImAddress());
        setMailAddress(entity.getMailAddress());
        setMailAddressBak(entity.getMailAddressBak());
        setAddress(entity.getAddress());
        setTask(entity.getTask());
        setIntroduction(entity.getIntroduction());
        setOutLine(entity.getOutLine());
        setPhoto(entity.getPhoto());
        setIsSigned(entity.getIsSigned());
        setRemark(entity.getRemark());
        if (entity.getRegDate() != null) {
            String date = sdf.format(entity.getRegDate());
            setRegDate(date);
        }
        setCategoryId(entity.getCategoryId());
        setCallTimes(entity.getCallTimes());
    }

    public byte[] getPhoto() {
        return photo;
    }

    public void setPhoto(byte[] photo) {
        this.photo = photo;
    }

    public Integer getCallTimes() {
        return callTimes;
    }

    public void setCallTimes(Integer callTimes) {
        this.callTimes = callTimes;
    }

    @Override
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

    public String getImAddress() {
        return imAddress;
    }

    public void setImAddress(String imAddress) {
        this.imAddress = imAddress;
    }

    public String getMailAddress() {
        return mailAddress;
    }

    public void setMailAddress(String mailAddress) {
        this.mailAddress = mailAddress;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getIsSigned() {
        return isSigned;
    }

    public void setIsSigned(Integer isSigned) {
        this.isSigned = isSigned;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhoneBak() {
        return phoneBak;
    }

    public void setPhoneBak(String phoneBak) {
        this.phoneBak = phoneBak;
    }

    public String getCellPhoneBak() {
        return cellPhoneBak;
    }

    public void setCellPhoneBak(String cellPhoneBak) {
        this.cellPhoneBak = cellPhoneBak;
    }

    public String getMailAddressBak() {
        return mailAddressBak;
    }

    public void setMailAddressBak(String mailAddressBak) {
        this.mailAddressBak = mailAddressBak;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public String getOutLine() {
        return outLine;
    }

    public void setOutLine(String outLine) {
        this.outLine = outLine;
    }

    @Override
    public List<String> toJsonArray(int index) {
        List<String> result = new ArrayList<String>();
        result.add(String.valueOf(index + 1));
        result.add(name);
        result.add(CodeUtil.getSexString(sex));
        result.add(birthday);
        result.add(idNo);
        result.add(major);
        result.add(style);
        result.add(cellPhone);
        result.add(mailAddress);
        result.add(String.valueOf(callTimes));

        return result;
    }

    @Override
    public String validate() {
        List<String> errorList = new ArrayList<String>();
        // 身份证
        if (!IdcardUtil.validateCard(idNo)) {
            errorList.add("身份证号码不正确");
        }

        if (name == null || name.isEmpty()) {
            errorList.add("姓名必须输入");
        } else if (name.length() > 16) {
            errorList.add("姓名长度不能超过16");
        }

        if (sex != 0 && sex != 1) {
            errorList.add("性别只能输入‘男’或‘女’");
        }

        if (!BaseUtil.isEmpty(birthday)) {
            if (BaseUtil.parseDate(birthday) == null) {
                errorList.add("生日日期格式或内容输入不正确");
            }
        }

        if (!BaseUtil.isEmpty(type) && type.length() > 32) {
            errorList.add("类别长度不能超过32");
        }

        if (!BaseUtil.isEmpty(major) && major.length() > 32) {
            errorList.add("主讲课程长度不能超过32");
        }

        if (price != null && price.floatValue() <= 0) {
            errorList.add("课酬必须大于0");
        }

        if (!BaseUtil.isEmpty(style) && style.length() > 64) {
            errorList.add("讲师风格长度不能超过64");
        }

        if (!BaseUtil.isEmpty(style) && style.length() > 64) {
            errorList.add("讲师风格长度不能超过64");
        }

        if (!BaseUtil.isEmpty(cellPhone) && !BaseUtil.checkCellPhone(cellPhone)) {
            errorList.add("手机号码填写不正确");
        }

        if (!BaseUtil.isEmpty(cellPhoneBak) && !BaseUtil.checkCellPhone(cellPhoneBak)) {
            errorList.add("助理手机号码填写不正确");
        }

        if (!BaseUtil.isEmpty(phone) && !BaseUtil.checkPhone(phone)) {
            errorList.add("电话号码填写不正确");
        }

        if (!BaseUtil.isEmpty(phoneBak) && !BaseUtil.checkPhone(phoneBak)) {
            errorList.add("助理电话号码填写不正确");
        }

        if (!BaseUtil.isEmpty(imAddress) && !BaseUtil.checkQQ(imAddress) && !BaseUtil.checkMSN(imAddress)) {
            errorList.add("QQ/MSN填写不正确");
        }

        if (!BaseUtil.isEmpty(mailAddress) && !BaseUtil.checkMail(mailAddress)) {
            errorList.add("邮箱填写不正确");
        }

        if (!BaseUtil.isEmpty(mailAddressBak) && !BaseUtil.checkMail(mailAddressBak)) {
            errorList.add("助理邮箱填写不正确");
        }
        if (!BaseUtil.isEmpty(address) && address.length() > 128) {
            errorList.add("地址长度不能超过128");
        }
        if (!BaseUtil.isEmpty(task) && task.length() > 2048) {
            errorList.add("合作过的课题长度不能超过2048");
        }
        if (!BaseUtil.isEmpty(introduction) && introduction.length() > 2048) {
            errorList.add("老师简介长度不能超过2048");
        }
        if (!BaseUtil.isEmpty(outLine) && outLine.length() > 2048) {
            errorList.add("课程大纲长度不能超过2048");
        }
        if (!BaseUtil.isEmpty(regDate)) {
            if (BaseUtil.parseDate(regDate) == null) {
                errorList.add("登记时间格式或内容输入不正确");
            }
        }
        if (!BaseUtil.isEmpty(remark) && remark.length() > 2048) {
            errorList.add("备注长度不能超过2048");
        }
        return getErrMsgForUI(errorList);
    }

    public void decodeChangeLine() {
        setTask(BaseUtil.decodeChangeLine(getTask()));
        setIntroduction(BaseUtil.decodeChangeLine(getIntroduction()));
        setOutLine(BaseUtil.decodeChangeLine(getOutLine()));
        setRemark(BaseUtil.decodeChangeLine(getRemark()));
    }
}
